package la.common.xml;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;

public class NamespaceContextMap implements NamespaceContext {

	private Map<String, String> map;
	
	public NamespaceContextMap(String[][] map) {
		this.map = new HashMap<String, String>();
		for(String[] entity : map) {
			this.map.put( entity[0], entity[1] );
		}
	}
	
    public String getNamespaceURI(String prefix) {
        if (prefix == null) throw new NullPointerException("Null prefix");
        String result = map.get( prefix );
        if( result == null ) {
        	result = XMLConstants.NULL_NS_URI; 
        }
        return result;
    }

    // This method isn't necessary for XPath processing.
    public String getPrefix(String uri) {
        throw new UnsupportedOperationException();
    }

    // This method isn't necessary for XPath processing either.
    public Iterator getPrefixes(String uri) {
        throw new UnsupportedOperationException();
    }

}